﻿using System;
using System.Windows.Input;
using Samurai.DAL;
using System.Collections.ObjectModel;
using Samurai.Infrastructure;

namespace Samurai.Client.Commands
{
    public class AddToRepositoryCommand : ICommand
    {
        public void Execute(object parameter)
        {
            if (parameter != null && !string.IsNullOrEmpty(parameter.ToString()))
            {
                var newRepository = Manager.Instance.AddRepository(parameter.ToString());

                _repositories.Add(newRepository);
                CrawlDirectoryCommand.Instance.Execute(null);
            }
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;
        private readonly ObservableCollection<Repository> _repositories;

        public AddToRepositoryCommand(ObservableCollection<Repository> repositories)
        {            
            _repositories = repositories;
        }
    }
}
